package live.yanxiaohui.mideng.procuder;

import live.yanxiaohui.mideng.MsgUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @Description 解决消息幂等
 * @CSDN https://blog.csdn.net/yxh13521338301
 * @Author： yanxh<br>
 * @Date 2020-06-29 10:19<br>
 * @Version 1.0<br>
 */
@RestController
@RequestMapping("/mideng")
public class MiDengProcuder {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    private static final String QUEUE_NAME = "game";

    @RequestMapping("/send")
    public String send(String id) throws Exception{
        // String id = UUID.randomUUID().toString();

        String msg = "测试消息幂等性";
        rabbitTemplate.convertAndSend("", QUEUE_NAME, msg, (message)->{
            message.getMessageProperties().setMessageId(id);
            return message;
        });
        return id;
    }
}
